// pages/poster/poster.js
import paltter from '../../platter/carc'
const app= getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showToast({
      title: '加载中...',
      icon:'none',
      duration:3000
    })
    let that =this
    let data ={
      starId:options.id,
      page:"pages/starDetail/starDetail"
    }
   let car =  new paltter().palette()
   car.views[1].url=options.backImg
   car.views[2].text=options.name
   console.log(wx.getStorageSync('userinfo').token)
   wx.request({
     url: 'https://lovewall.needyoutd.com/api/Qrcode',
     method:'POST',
     data:data,
     header:{
      Authorization:wx.getStorageSync('userinfo').token
     },
     success(res){
       console.log(res)
       car.views[5].url=res.data.data.qrcode
       that.setData({
        template:car
      })
   
     }
   })
    
  },
  saveImg(){
    this.saveImage()
  },
  onImgOK(e) {
    var that = this
    var imagePath = e.detail.path;
    that.setData({
      imagePath: imagePath
    })
  },
  saveImage() {
    var that = this
    wx.saveImageToPhotosAlbum({
      filePath: that.data.imagePath,
      success: (res) => {
        that.setData({
          poster_hidden: true
        })
        wx.showToast({
          title: '已保存到相册',
        })
      }, fail() {
        wx.showModal({
          title: '保存失败！',
          content: '请检查相册访问是否授权',
          success(res) {
            if (res.confirm) {
              wx.openSetting({
                success(res) {
                  console.log(res.authSetting)
                }
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})